<?php
/**
 * Created by 王跃达.
 * User: 小马出行
 * Date: 2017/8/24
 * Time: 16:17
 */

namespace app\api\logic;


use app\api\model\ZoneModel;
use my\Rsa;
use think\Model;

class ZoneLogic extends Model
{


    public function __construct()
    {
        parent::__construct();

    }

    /*
     * 通过坐标获取信息
     */
    public function getZoneByLocal($gd_local)
    {

        if (!empty($gd_local)) {
            $result = get_info_by_local($gd_local);
            $result = json_decode($result, true);
            if ($result['status'] == 1) {
                $city = $result['regeocode']['addressComponent']['city'];
                $district = $result['regeocode']['addressComponent']['district'];
                $zoneModel = new ZoneModel();
                $zone = $zoneModel->getZoneByLocal($city, $district);//返回zone表的信息
                if (!empty($zone)) {
                    $zone["local"] = $gd_local;
                    $zone['province'] = $result['regeocode']['addressComponent']['province'];
                    $zone['city'] = $result['regeocode']['addressComponent']['city'];
                    $zone['district'] = $result['regeocode']['addressComponent']['district'];
                    $zone["place_name"] = $result['regeocode']['pois'][0]['name'];
                    return $zone;
                }
                return null;

            }
        }
        return array("status" => 0, "msg" => "定位信息错误1");
    }

    /**
     * 根据id获取运营区域信息
     * @param $id
     * @param $field
     * @return mixed
     * */
    public function getZoneById($id,$field='*')
    {
        $zoneModel = new ZoneModel();
        $map['zone_id'] = $id;
        return $zoneModel->getZone($map,$field,false);
    }
}